package au.edu.utas.yu_qiao_group.luckyman.utils;


import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Currency;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.InverseMethod;
import au.edu.utas.yu_qiao_group.luckyman.db.draws.DrawDTO;

public class FormatUtils {
  private static final  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

  public static String formatCurrency (long price) {
    final NumberFormat currencyInstance = NumberFormat.getCurrencyInstance();
    currencyInstance.setCurrency(Currency.getInstance("AUD"));
    return currencyInstance.format(price);
  }

  public static String dateToString (long date) {
    return sdf.format(date);
  }

  public static HashMap<Integer, String> statusMap = new HashMap<Integer, String>(){{
    put(DrawDTO.STATUS_PENDING, "PENDING");
    put(DrawDTO.STATUS_FINISHED, "FINISHED");
    put(DrawDTO.STATUS_CANCELLED, "CANCELLED");
  }};

  public static String formatDrawStatus (int status) {
    return FormatUtils.statusMap.containsKey(status) ? FormatUtils.statusMap.get(status) : "unknown status: " + String.valueOf(status);
  }

  @InverseMethod("stringToInt")
  public static String intToString (int newValue) {
    String s = String.valueOf(newValue);
    return s == "0" ? "" : s;
  }

  public static int stringToInt (String newValue) {
    return TextUtils.isEmpty(newValue) ? 0 : Integer.parseInt(newValue);
  }

  @InverseMethod("boolToInt")
  public static boolean intToBool (int newValue) {
    return newValue == 0 ? false : true;
  }

  public static int boolToInt (boolean newValue) {
    return newValue ? 1 : 0;
  }

}
